<html>
<head>
    <title>Search For</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <script type="text/javascript" src="<?=base_url()?>resource/js/jquery.js"></script>
    
    <link rel="stylesheet" href='<?=base_url()?>resource/css/style.css' type="text/css"/>
    
    <link rel="stylesheet" type="text/css" href="<?=base_url()?>resource/css/jquery.datetimepicker.css" />
    <script src="<?=base_url()?>resource/js/jquery.datetimepicker.js"></script>
    
    <link rel="stylesheet" type="text/css" href="<?=base_url()?>resource/css/jquery.autocompleter.css" />
    <script src="<?=base_url()?>resource/js/jquery.autocompleter.js"></script>
</head>
<body>
    <div class="choice-header">
        <h3><?=$title?></h3>
    </div>
    <div class="list-div">
        <?php echo form_open('profile/choice_company'); ?>
        <table class="top-table">
            <tr>
                <td>Company List</td>
                <td width="240" class="center"><input type="text" placeholder="input search condition" 
                    name="condition" value="<?=$condition?>"/></td>
                <td width="90" class="center"><input type="submit" value="Search" /></td>
                <td width="110" class="center"><input type="button" value="New" id="new"/></td>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <input type="button" id="submit" value="submit" class="submit" />
        <table class="list-table">
            <tr>
                <th width="40">Check</th>
                <th width="100">Company Name</th>
                <th>Industry</th>
                <th width="100">Contact Person</th>
                <th width="100">Position</th>
                <th width="60">Contact No</th>
            </tr>
            <?php foreach ($orders as $key => $value) {?>
            <tr>
                <td>
                    <input type="radio" name="companyid" value="<?=$value['id']?>">
                    <input type="hidden" id="companyname<?=$value['id']?>" value="<?=$value['name']?>" />
                </td>
                <td><?=$value['name']?></td>
                <td><?=$value['industryname']?></td>
                <td><?=$value['person']?></td>
                <td><?=$value['position']?></td>
                <td><?=$value['number']?></td>
            </tr>
            <?php }
            if(count($orders) == 0){?>
            <tr>
                <td colspan="6">
                    NO DATA
                </td>
            </tr>
            <?php }?>
        </table>
    </div>
<script>
$("#submit").click(function(){
    var nameobj = window.opener.document.getElementById("name"); 
    var companyidobj = window.opener.document.getElementById("companyid");
    
    var id = $("input[name='companyid']:checked").val();
    
    if(id != undefined){
        nameobj.value = $("#companyname"+id).val();
        companyidobj.value = id;
    }
    window.close();
});

$("#new").click(function(){
    var storage = window.localStorage; 
    storage.setItem("currentid","company");
    var url = '<?=base_url()?>index/new_company';
    window.opener.location.href=url; //重新定位父页面
    window.close();
});
</script>
</body>
</html>